import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
//import locale from 'element-ui/lib/locale/lang/en' // lang i18n 国际化默认英文
// 引入element-ui的中文语言包
import zhCn from 'element-ui/lib/locale/lang/zh-CN'; // 中文语言包//中文包


import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// 判断我们是生产环境下，使用mock数据
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}
// 全局注册，设置语言包
Vue.use(ElementUI, { zhCn })

Vue.config.productionTip = false
//注册自定义指令，控制我们的权限
Vue.directive('permission', {//注册自定义指令是不需要加 v- 的
  //inserted会在我们的元素插入dom之后执行
  inserted: function (el, binding) {
    //console.log(binding);
    //console.log(el, binding);
    //el:当前指令所在的dom元素
    //binding:是v-permission='表达式' 表达式的信息
    const points =  store.state.user.userInfo?.userPermissions || []
    //console.log(points);
    //如果points中不包含binding.value
    //删除或者禁用该元素
    //console.log(binding.value);
    if(!points.includes(binding.value)){
      //el.remove()
      el.disabled = true
    }
  }
})
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
